package com.jinsilu.freight.ui.activity;

import android.text.TextUtils;
import android.view.View;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.jinsilu.freight.common.MyVBActivity;
import com.jinsilu.freight.databinding.ActivitySuggestionsBinding;
import com.jinsilu.freight.helper.CommonHelper;
import com.jinsilu.freight.helper.InputTextHelper;
import com.jinsilu.freight.http.model.HttpData;
import com.jinsilu.freight.http.request.SuggestionApi;
import com.jinsilu.freight.http.response.UserInfoBean;

/**
 * 投诉建议
 *
 * @author yangyang
 * @time 2020-11-16 17:00
 */
public class SuggestionsActivity extends MyVBActivity<ActivitySuggestionsBinding> {

    @Override
    protected void initView() {
        setOnClickListener(binding.tvBtnSubmit);
        InputTextHelper.with(this)
                .addView(binding.etSuggestionsContent)
                .setMain(binding.tvBtnSubmit)
                .build();
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        if (v == binding.tvBtnSubmit) {
            String content = binding.etSuggestionsContent.getText().toString().trim();
            if (TextUtils.isEmpty(content)) {
                toast("请输入您的建议");
                return;
            }
            suggestions(content);
        }
    }

    private void suggestions(String content) {
        if (1 != CommonHelper.getUserInfo().getCertificationStatus()){
            toast("未认证的用户无法进行投诉");
            return;
        }
        UserInfoBean userInfoBean = CommonHelper.getUserInfo();
        // 投诉建议
        EasyHttp.post(this)
                .api(new SuggestionApi()
                        .setDriverName(userInfoBean.getName())
                        .setDriverPhone(userInfoBean.getPhone())
                        .setDriverPlateNumber(userInfoBean.getVehicleNumber())
                        .setIdea(content))
                .request(new HttpCallback<HttpData<Void>>(this) {
                    @Override
                    public void onSucceed(HttpData<Void> data) {
                        toast(data.getMessage());
                        finish();
                    }
                });
    }
}
